{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true,
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3.1411926536057937\n"
     ]
    }
   ],
   "source": [
    "# 圆周率计算\n",
    "total = 0\n",
    "n = 1\n",
    "\n",
    "for x in range(1, 5000, 2):\n",
    "    if (n % 2) == 1:\n",
    "        total += 1/x\n",
    "    else:\n",
    "        total -= 1/x\n",
    "\n",
    "    n += 1\n",
    "\n",
    "print(total * 4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6\n",
      "10\n",
      "15\n"
     ]
    }
   ],
   "source": [
    "def add(*n):\n",
    "    total = 0\n",
    "\n",
    "    for x in n:\n",
    "        total += x\n",
    "\n",
    "    return total\n",
    "\n",
    "print(add(1, 2, 3))\n",
    "print(add(1, 2, 3, 4))\n",
    "\n",
    "lst = [1, 2, 3, 4, 5]\n",
    "print(add(*lst))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello, James Bound!\n",
      "Hello, Tomas Tod!\n",
      "Hello, James Bound!\n",
      "Hello, James Bound!\n"
     ]
    }
   ],
   "source": [
    "def sayHello(fname=\"James\", lname=\"Bound\"):\n",
    "    return f\"Hello, {fname} {lname}!\"\n",
    "\n",
    "print(sayHello())\n",
    "print(sayHello(\"Tomas\", \"Tod\"))\n",
    "print(sayHello(lname=\"Bound\", fname=\"James\"))\n",
    "\n",
    "d = {\n",
    "    \"fname\": \"James\",\n",
    "    \"lname\": \"Bound\"\n",
    "}\n",
    "print(sayHello(**d))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}